package com.dearbinge.data.service.impl.bankCard;

import com.baomidou.mybatisplus.plugins.Page;
import com.dearbinge.data.api.bankCard.BankCardService;
import com.dearbinge.data.dao.BankCardMapper;
import com.dearbinge.data.pojo.bankCard.BankCard;
import com.dearbinge.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service(value = "bankCardService")
public class BankCardServiceImpl implements BankCardService {

    @Autowired
    private BankCardMapper bankCardMapper;

    @Override
    public Integer insert(BankCard bankCard) {
        Integer dataCode = bankCardMapper.insert(bankCard);
        return dataCode;
    }

    @Override
    public Integer update(BankCard bankCard) {
        Integer dataCode = bankCardMapper.update(bankCard);
        return dataCode;
    }

    @Override
    public Integer delete(Integer id) {
        Integer dataCode = bankCardMapper.delete(id);
        return dataCode;
    }

    @Override
    public Page getByPage(String userId, Integer pageNo, Integer pageSize) {
        pageNo = PageUtils.getDefaultValues(pageNo, 1);
        pageSize = PageUtils.getDefaultValues(pageSize, 10);
        Page<BankCard> page = new Page(pageNo,pageSize);
        Integer count = bankCardMapper.count(userId);
        List<BankCard> list = bankCardMapper.getByPage(userId,page);
        page.setTotal(count);
        page.setRecords(list);
        return page;
    }

    @Override
    public Integer count(String userId) {
        Integer count = bankCardMapper.count(userId);
        return count;
    }
}
